<include file="../header" />
<body class="J_scroll_fixed">

<style type="text/css">
    .btn,.btn-danger,.btn-info,.btn-success,.btn-warning{
        width: 80px;
        /*height: 18px;*/
        padding: 2px 0px 2px 0px;
        margin: 1px 0px 1px 0px;
    }
</style>
<script language="javascript" src="/Template/js/ImgPreview.js"></script>
<link type="text/css" rel="stylesheet" href="/Template/js/jeDate/test/jeDate-test.css">
<link type="text/css" rel="stylesheet" href="/Template/js/jeDate/skin/jedate.css">
<script type="text/javascript" src="/Template/js/jeDate/src/jedate.js"></script>
<script type="text/javascript">

    $(function() {
        jeDate("#instore_month",{
            format: "YYYY-MM"
        });

        $("input[name=checkAll]").click(function() {
            var checkboxs = $("input.checkItem");
            if($("input[name=checkAll]").is(':checked')) {
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = true;
                }
            }else{
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = false;
                }
            }
        });

        $("a[name=downloadExcel]").click(function() {
            var checkboxs = $("input.checkItem");
            var id = "";
            for (var i = 0; i < checkboxs.length; i++) {
                if(checkboxs[i].checked == true){
                    if(id != ""){
                        id += ",";
                    }
                    id += checkboxs[i].name;
                }
            }
            if(id == ""){
                alert("未选择单据");
                $("input[name=checkAll]").focus();
                return false;
            }
            var url = "/admin/Reporting/getTable?name=workorder&id=" + id;
            window.location.href = url;
        });


        $(".auditList").click(function() {
            var checkboxs = $("input.checkItem");
            var id = "";
            var count = 0;
            for (var i = 0; i < checkboxs.length; i++) {
                if(checkboxs[i].checked == true){
                    if(id != ""){
                        id += ",";
                    }
                    id += checkboxs[i].name;
                    count++;
                }
            }
            if(id == ""){
                alert("未选择单据");
                $("input[name=checkAll]").focus();
                return false;
            }
            if (confirm("确定出库审核 " + count +" 条表单？")) {
                $(".auditList").hide();
                var data = {};
                data.id = id;
                $.ajax({
                    url:"/admin/Reporting/audit",
                    type:"post",
                    data:data,
                    dataType:"JSON",
                    beforeSend:function(){
                        $("#loadingToast").show();
                    },
                    complete:function(){
                        $('#loadingToast').hide();
                    },
                    success:function(data){
                        if(data.code != 200) {
                            alert(data.msg);
                            return false;
                        }else{
                            alert("成功审核 "+ data.count +" 单");
                        }
                        window.location.href = "/admin/Reporting/workorder";
                    },
                })
            } else {
                return false;
            }

        });

    });
</script>
<form class="well form-search" method="post" style="float:left;width:100%;" action="{:U('Reporting/workorder')}">
    <div class="search_type cc mb10">
        <div class="mb10">
        <span class="mr20">
            <!--单号：<input type="text" name="ps#purchase_no-like" value="{$purchase_no}" />-->
            状态：
            <select style="width: 90px" name="s#outstore_status">
                {:getFormDictSelectOptionHtml($outstore_status,'outstoreStatus','all',-1)}
            </select>
            &nbsp;&nbsp;&nbsp;
            仓库：
            <select style="width: 200px" name="st#store_id">
                  {:getCommonSelectOptionHtml($store_id, "Store", "store_id", "store_name", null, $user['enterprise_code'], 1)}
            </select>
            &nbsp;&nbsp;&nbsp;
            业务员：
            <select style="width: 145px" name="wo#sales_id">
                {:getEmployeeSelectOptionHtml($user['enterprise_code'],"2",-1, $sales_id)}
            </select>
            <br/><br/>
            出库开始时间：<input type="text" style="width: 110px" class="date J_date" name="s#outstore_date-egt" value="{$begin_date}"/>
            &nbsp;&nbsp;
            出库结束时间：<input style="width: 110px" type="text" class="date J_date" name="s#outstore_date-elt" value="{$end_date}"/>
            &nbsp;
            入库月份：<input style="width: 80px" type="text" class="jeinput" id="instore_month" name="instore_month" value="{$instore_month}" placeholder="YYYY-MM">
            &nbsp;
            <button class="btn btn-primary">搜索</button>
            <a class="btn" href="{:U('Reporting/workorder')}">重置</a>
        </span>
        </div>
    </div>
</form>
<div class="wrap J_check_wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:U('Reporting/workorder')}">相关信息</a></li>
        <!--<li><a href="{:U('Purchase/purchaseMaterial')}">新增物料采购</a></li>-->
        <!--<li><a href="{:U('Purchase/purchaseFinishedProduct')}">新增成品采购</a></li>-->
        <li><a name="downloadExcel" style="cursor: pointer;"><span style="text-decoration:underline;">下载</span>选中报表</a></li>
        <li><a class="auditList" style="color: #ED7667; cursor: pointer;"><span style="text-decoration:underline;">出库审核</span>选中表单</a></li>
    </ul>
    <table class="table table-hover table-bordered">
        <thead>
        <tr>
            <th style="min-width: 10px; width: 10px"><input type="checkbox" name="checkAll"></th>
            <th style="min-width: 50px;">名称</th>
            <th style="min-width: 50px; width: 150px">仓库</th>
            <th style="min-width: 50px; width: 130px">工单号</th>
            <th style="min-width: 50px; width: 100px">患者信息</th>
            <th style="min-width: 40px; width: 40px">规格</th>
            <th style="min-width: 40px; width: 40px">数量</th>
            <!--<th style="min-width: 60px; width: 60px">销售单价</th>-->
            <!--<th style="min-width: 50px; width: 50px">折扣率</th>-->
            <!--<th style="min-width: 80px; width: 80px">生产日期</th>-->
            <!--<th style="min-width: 80px; width: 80px">有效期至</th>-->
            <th style="min-width: 50px; width: 70px">销售金额</th>
            <th style="min-width: 50px; width: 170px">收款情况</th>
            <th style="min-width: 50px; width: 70px">成本</th>
            <th style="min-width: 60px; width: 60px">业务员</th>
            <th style="min-width: 60px; width: 60px">审核人</th>
            <th style="min-width: 120px; width: 120px">状态</th>
            <th style="min-width: 50px; width: 50px">操作</th>
        </tr>
        </thead>
        <tbody>
        <foreach name="list" item="vo">
            <tr>
                <php>
                    $checkName = $vo["instore_id"];
                </php>
                <td><input type="checkbox" class="checkItem" name="{$checkName}"></td>
                <if condition = "$vo['outstore_name'] eq ''">
                    <td>{$vo.inventory_name}</td>
                    <else/>
                    <td>{$vo.outstore_name}</td>
                </if>
                <td>{$vo.store_name}</td>
                <td>{$vo.workorder_no}</td>
                <td>{$vo.patient_name}<br/>{$vo.sex}，{$vo.age}岁</td>
                <td>{$vo.spec}</td>
                <td>{$vo.number}&nbsp;{$vo.unit}</td>
                <!--<td>{$vo.price}&nbsp;元</td>-->
                <!--php>
                    $discont = (int)($vo["sale_price"] * 100 / $vo["price"])."%";
                </php-->
                <!--<td><a name="discont">{$discont}</a></td>-->
                <!--<td>{$vo.production_date}</td>-->
                <!--<td>{$vo.expiry_date}</td>-->
                <td>{$vo.price}&nbsp;元</td>
                <php>
                    $percent = (int)($vo["payment_price"] * 100 / $vo["price"])."%";
                </php>
                <if condition = "$vo['payment_status'] neq ''">
                    <td>{$vo.payment_status}：{$vo.payment_price}&nbsp;元&nbsp;（{$percent}）</td>
                    <else/>
                    <td></td>
                </if>
                <td>{$vo.cost}&nbsp;元</td>
                <td>{$vo.sales_name}</td>
                <td>{$vo.auditor_name}</td>
                <!--if condition = "$vo['outstore_status'] eq '-1'">
                    <td style="color: #5993df">待审核</td>
                </if-->
                <if condition = "$vo['outstore_status'] eq '-1'">
                    <td style="color: #df6b5f">待审核</td>
                </if>
                <if condition = "$vo['outstore_status'] eq '1'">
                    <td style="color: #1dccaa">已审核<br>{$vo.outstore_audit_time} </td>
                </if>
                <td>
                    <php>
                        $outstoreStatus = "";
                        $role = explode(',',$user["role"]);
                        //if($user["employee_id"] == $vo["sales_id"]){
                        //    if($vo["outstore_status"] == -1 ){
                        //    $outstoreText = "销售出库";
                        //    $outstoreStatus = 1;
                        //    }else{
                        //    $outstoreText = "已出库";
                        //    $outstoreStatus = -1;
                        //    }
                        //}
                        if(in_role($role,"4")){
                            if($vo["outstore_status"] == -1 ){
                            $outstoreText = "出库审核";
                            $outstoreStatus = 1;
                            }
                            if($vo["outstore_status"] == 1){
                            $outstoreText = "出库反审核";
                            $outstoreStatus = 2;
                            }
                        }
                    </php>
                    <if condition="$outstoreStatus eq 1">
                        <a class="btn btn-info" href='{:U("workorder/outstore",array("id"=>$vo["product_id"]))}'>{$outstoreText}</a>
                    </if>
                    <if condition="$outstoreStatus eq 2">
                        <a class="btn btn-danger" href='{:U("workorder/outstore",array("id"=>$vo["product_id"]))}'>{$outstoreText}</a>
                    </if>
                    <if condition="$outstoreStatus eq -1">
                        <a disabled="disable" style="background-color: #93949c" class="btn btn-info">{$outstoreText}</a>
                    </if>
                </td>
            </tr>
        </foreach>
        </tbody>
    </table>
    <div class="pagination">{$page}</div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>